<div>
    <table id="doctorTable" lay-filter="doctorTable">
    </table>
</div>

<div class="site-text" style="margin: 5%; display: none" id="window1">
    <form class="layui-form" id="updatedoc" lay-filter="updatedoc">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" id="anoName" name="anoName" autocomplete="off" placeholder="请输入姓名"
                       class="layui-input">
            </div>
            <br> <br>
            <label class="layui-form-label">身份证号码</label>
            <div class="layui-input-block">
                <input type="text" id="idCard" name="idCard" autocomplete="off" placeholder="请输入身份证号码"
                       class="layui-input">
            </div>
            <br> <br>
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-block">
                <input type="text" id="phoneNum" name="phoneNum" autocomplete="off" placeholder="请输入手机号码"
                       class="layui-input">
            </div>
            <br> <br>
            <label class="layui-form-label">科室</label>
            <div class="layui-input-block">
                <input type="text" id="section" name="section" autocomplete="off" placeholder="请输入科室"
                       class="layui-input">
            </div>
            <br> <br>
            <label class="layui-form-label">职称</label>
            <div class="layui-input-block">
                <input type="text" id="ttitle" name="ttitle" autocomplete="off" placeholder="请输入职称"
                       class="layui-input">
            </div>

        </div>
    </form>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
</script>
<script>
    layui.use(['table', 'layer', 'jquery'], function () {
        var table = layui.table;
        var $ = layui.jquery
        var form = layui.form
        table.render({
            elem: '#doctorTable'
            , height: 600
            , url: '/doctor/all' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'id', title: 'ID', width: 100, sort: true, fixed: 'left'}
                , {field: 'doctorname', title: '医生用户名', width: 130}
                , {field: 'anoName', title: '姓名', width: 120}
                , {field: 'idCard', title: '身份证号码', width: 100}
                , {field: 'phoneNum', title: '手机号码', width: 100}
                , {field: 'inserttime', title: '添加时间', width: 230}
                , {field: 'section', title: '科室', width: 130}
                , {field: 'ttitle', title: '职称', width: 130}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 70}

            ]]
        });
        table.on('tool(doctorTable)', function (obj) {
            var data = obj.data
            if (obj.event === 'update') {
                form.val("updatedoc", {
                    "anoName": data.anoName,
                    "idCard": data.idCard,
                    "phoneNum": data.phoneNum,
                    "section": data.section,
                    "ttitle": data.ttitle
                });
                layer.open({
                    type: 1
                    , content: $("#window1")
                    , btn: '确定'
                    , btnAlign: 'c' //按钮居中
                    , area: ['500px', '500px']
                    , shade: 0 //不显示遮罩
                    , yes: function () {
                        var data1 = form.val("updatedoc");
                        var postdata = {
                            "id": data.id,
                            "anoName": data1.anoName,
                            "idCard": data1.idCard,
                            "phoneNum": data1.phoneNum,
                            "section": data1.section,
                            "tTitle": data1.ttitle
                        }
                        $.ajax({
                            url: '/doctor/update',
                            type: 'post',
                            contentType: "application/json",
                            data: JSON.stringify(postdata),
                            success: function (data) {
                                document.getElementById("updatedoc").reset();
                                table.render({
                                    elem: '#doctorTable'
                                    , height: 600
                                    , url: '/doctor/all' //数据接口
                                    , page: true //开启分页
                                    , cols: [[ //表头
                                        {field: 'id', title: 'ID', width: 100, sort: true, fixed: 'left'}
                                        , {field: 'doctorname', title: '医生用户名', width: 130}
                                        , {field: 'anoName', title: '姓名', width: 120}
                                        , {field: 'idCard', title: '身份证号码', width: 100}
                                        , {field: 'phoneNum', title: '手机号码', width: 100}
                                        , {field: 'inserttime', title: '添加时间', width: 230}
                                        , {field: 'section', title: '科室', width: 130}
                                        , {field: 'ttitle', title: '职称', width: 130}
                                        , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 70}

                                    ]]
                                });
                            },
                        })

                        //data是默认值
                        layer.closeAll();

                    }
                });
            }


        })
    });
</script>